<h1>User Manager</h1>
<?php
if (checkrank(1, $operator = '==') or checkrank(2, $operator = '==')) {
	echo "<p><a href='panel.php?page='>User List</a> | <a href='panel.php?page=register'>New User</a></p> ";
	if (isset($_GET["userdisplay"])) { 
		$userdisplay  = $_GET["userdisplay"]; 
	} else { 
		$userdisplay=1; 
	} 
	$start_from = ($userdisplay-1) * 20; 
	$sql = "SELECT * FROM users ORDER BY username ASC LIMIT $start_from, 20"; 
	$result = mysql_query($sql); 
	echo"<table>
	<tr><td>Name</td><td>EMail</td><td>Name</td><td>Rank</td><td>Actions</td></tr>";
	while ($row = mysql_fetch_assoc($result)) { 
	    if (checkrank($row['rank'], $operator = '<')) {
			$editable = 0;
		} else { 
		    $nameofuser = $row['username'];
		}
		echo "<tr>
		<td>".$row['username']."</td>
		<td>".$row['email']."</td>
		<td>".$row['firstName']." ".$row['lastName']."</td>
		<td>".$row['rank']."</td>";
		 if (checkrank($row['rank'], $operator = '<')) {

		} else { 
		    echo"<td><a href='panel.php?username=".$row['username']."&action=editprofile'>Edit</a> | Delete</td>";
		}
		echo "</tr>";
	}
	echo "</table>";
	$sql = "SELECT COUNT(username) FROM users"; 
	$rs_result = mysql_query($sql); 
	$row = mysql_fetch_row($rs_result); 
	$total_records = $row[0]; 
	$total_pages = ceil($total_records / 20); 
	 
	for ($i=1; $i<=$total_pages; $i++) { 
				echo "<a href='?page=usermanager&userdisplay=".$i."'>".$i."</a> "; 
	}
} else {
	header("Location: panel.php?page=accessdenied-show");
}
?>